import pygame


class Ship:

    def __init__(self, game):
        self.screen = game.screen
        self.screen_rect = game.screen.get_rect()

        self.image = pygame.image.load("../alien_invasion/images/ship.png")
        self.image = pygame.transform.scale(self.image, (30, 40))
        self.image = pygame.transform.rotate(self.image, -90)
        self.image_rect = self.image.get_rect()

        self.image_rect.midleft = self.screen_rect.midleft

        self.movingRight = False
        self.movingLeft = False
        self.movingUp = False
        self.movingDown = False

    def update(self):
        if self.movingLeft and self.image_rect.left >= 0:
            self.image_rect.x -= 1
        if self.movingRight and self.image_rect.right \
                <= self.screen_rect.right:
            self.image_rect.x += 1
        if self.movingUp and self.image_rect.y >= 0:
            self.image_rect.y -= 1
        if self.movingDown and self.image_rect.bottom \
                <= self.screen_rect.bottom:
            self.image_rect.y += 1

    def blitme(self):
        self.screen.blit(self.image, self.image_rect)
